import { config } from 'dotenv';
import { TypeOrmModuleOptions } from '@nestjs/typeorm';
import { JwtModuleOptions } from '@nestjs/jwt';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';

config({
    path: `.env.${process.env.NODE_ENV || 'development'}`
});


// 常规配置
export const configuration = () => ({
    port: parseInt(process.env.PORT, 10) || 3000
    // 其他配置...
});

// 数据库相关
export const typeOrmConfig: TypeOrmModuleOptions = {
    type: 'mysql',
    host: process.env.DATABASE_HOST,
    port: parseInt(process.env.DATABASE_PORT, 10),
    username: process.env.DATABASE_USER,
    password: process.env.DATABASE_PASSWORD,
    database: process.env.DATABASE_NAME,
    entities: ['dist/**/*.entity{.ts,.js}'],
    autoLoadEntities: process.env.NODE_ENV === 'production' ? false : true,
    synchronize: process.env.NODE_ENV === 'production' ? false : true,
};

// 加密相关
export const jwtConfig: JwtModuleOptions = {
    secret: 'sadasdasd',
    signOptions: {
        expiresIn: '7d',
    },
    global: true,
};

// Swagger 配置
export const swaggerConfig = new DocumentBuilder()
    .setTitle('API Documentation')
    .setDescription('The API description')
    .setVersion('1.0')
    .addBearerAuth()  // 如果你使用 JWT 认证
    .build();
